package com.easybbs.controller.news;

import com.easybbs.controller.base.BaseController;
import com.easybbs.entity.dto.NewsDTO;
import com.easybbs.entity.dto.PyReadDTO;
import com.easybbs.entity.po.NewsPO;
import com.easybbs.entity.vo.ResponseVO;
import com.easybbs.service.impl.NewsService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.xml.ws.Response;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/news")
public class NewController extends BaseController {

    @Resource
    NewsService newsService;


    //@PostMapping("/uploadFile")
    //public ResponseVO<String> uploadFile(MultipartFile file) {
    //    return getSuccessResponseVO(newsService.uploadFile(file));
    //}

    @PostMapping("add")
    public ResponseVO<String> addNews(@RequestBody NewsPO newsPO){
        newsService.addNews(newsPO);
        return getSuccessResponseVO("ccccc");
    }

    @GetMapping("get")
    public ResponseVO<Map<String, List<NewsPO>>> get(){
        return getSuccessResponseVO(newsService.get());
    }

    @GetMapping("getNewsDetail")
    public ResponseVO<NewsPO> getNewsDetail(int newsId){
        return getSuccessResponseVO(newsService.getNewsDetail(newsId));
    }


    /**
     *
     * @param url
     * @param tag
     * @return
     */
    @PostMapping("pyRead")
    public ResponseVO<String> pyRead(@RequestBody PyReadDTO pyReadDTO){
        try {
            return getSuccessResponseVO(newsService.pyRead(pyReadDTO));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

}
